package edu.uc.ui;

import java.util.Calendar;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 
 * @author ckattick
 * displays logged in screen
 */
public class LoggedInScreen extends CeasBaseScreen {
	// add local variables
	private EditText archive;
	private Button clear;
	private Button commit;
	private CheckBox timeStub;
	private TextView result;
	private Calendar currentTime = Calendar.getInstance();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.loggedin);
		initComponents();
	}

	// provide intiComponents method to free up the onCreat method
	private void initComponents() {
		// connect local variables to view components
		archive = (EditText) findViewById(R.id.archive);
		clear = (Button) findViewById(R.id.clear);
		commit = (Button) findViewById(R.id.btncommit);
		timeStub = (CheckBox) findViewById(R.id.timeStamp);
		result = (TextView) findViewById(R.id.viewResult);

		// declare button listeners with inner class view
		commit.setOnClickListener(new OnClickListener() {
			// @Override
			public void onClick(View v) {
				Commit();

			}
		});
		clear.setOnClickListener(new OnClickListener() {
			// @Override
			public void onClick(View v) {
				ClearText();

			}
		});
	}

	// method to clear the archive text field instead of have to back space

	public void ClearText() {
		archive.setText("");
	}

	// this method doesn't persist yet but adds the value to result TextView
	public void Commit() {
		if (archive.getText().toString().length() == 0) {
			result.setText("Invalid Input, please write something before commiting");
		} else {
			// clear the input textbox
			ClearText();
			// checks to see if user wants a timestamp added to their comment
			if (timeStub.isChecked()) {
				result.setText(archive.getText().toString() + "--"
						+ currentTime.getTime());
			} else {
				result.setText(archive.getText().toString());
			}

		}
	}
}
